<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	    <title>KeyListener Test</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

        <link type="text/css" rel="stylesheet" href="../../build/logger/assets/logger.css">
        <style>
            #out {
                padding: 10px;
                width:300px;
            }
        </style>

		<script type="text/javascript" src="../../build/yahoo/yahoo.js"></script>
		<script type="text/javascript" src="../../build/dom/dom.js"></script>
		<script type="text/javascript" src="../../build/event/event.js"></script>

        <script type="text/javascript" src="../../build/dragdrop/dragdrop-min.js"></script>
        <script type="text/javascript" src="../../build/logger/logger-min.js"></script>
		<script type="text/javascript" src="../../build/container/container.js"></script>
		<script type="text/javascript">

        (function() {

            var Y = YAHOO, E = YAHOO.util.Event,
                pd = E.preventDefault, sp = E.stopPropagation;



            function onKey(el, fn, o, override) {

                Y.log('onKey');

                var prevented = false; stopped = false, keydown = true;


                E.preventDefault = function(e) {
                    prevented = true;
                    pd(e);
                };

                E.stopPropagation = function(e) {
                    stopped = true;
                    sp(e);
                };

                var scope = el;
                if (override) {
                    if (override === true) {
                        scope = o;
                    } else {
                        scope = override;
                    }
                }

                E.on(el, 'keydown', function(e) {
                    Y.log('keydown');
                    keydown = true;
                    fn.call(scope, E.getEvent(e, el), o);
                });


                E.on(el, 'keypress', function(e) {
                    Y.log('keypressed -- stopped: ' + stopped + ', prevented: ' + prevented);
                    if (stopped) {
                        sp(e);
                    }

                    if (prevented) {
                        pd(e);
                    }

                    if (!keydown) {
                        fn.call(scope, E.getEvent(e, el), o);
                    }
                });

                // E.preventDefault = pd;
                // E.stopPropagation = sp;
            }

            E.onDOMReady(function() {
                var oLogger = new Y.widget.LogReader();

                Y.log('DOMReady');

                onKey(document, function(e) {
                    E.preventDefault(e);
                    // Y.log('done');
                });
            });

            /*

            void(function() {


                YAHOO.util.Dom.get('out').innerHTML = YAHOO.lang.dump(YAHOO.util.KeyListener.KEY);

                E.on(document, "keydown", function(e) {
                    YAHOO.log("************************************************");
                    YAHOO.log("keydown: " + E.getCharCode(e));
                    // E.stopEvent(e);
                });
                E.on(document, "keyup", function(e) {
                    YAHOO.log("keyup: " + E.getCharCode(e));
                    // E.stopEvent(e);
                });
                E.on(document, "keypress", function(e) {
                    YAHOO.log("keypress: " + E.getCharCode(e));
                    YAHOO.log("************************************************");
                    // E.stopEvent(e);
                });

                function onKeyEvent(p_sType, p_aArgs) {
                
                    var oEvent = p_aArgs[1],
                        nCharCode = E.getCharCode(oEvent);
                
                    YAHOO.log("EVENT:" + oEvent.type + ", KEY CODE: " + nCharCode);
                
                }

                var oKeyListener1 = new YAHOO.util.KeyListener(
                                                       document, 
                                                       { keys:27 }, 
                                                       onKeyEvent, 
                                                       "keydown"
                                                   ); 
                                                   
                oKeyListener1.enable();


                var oKeyListener2 = new YAHOO.util.KeyListener(
                                                       document, 
                                                       { keys:27 }, 
                                                       onKeyEvent, 
                                                       "keyup"
                                                   ); 

                oKeyListener2.enable();
                

                var oKeyListener3 = new YAHOO.util.KeyListener(
                                                       document, 
                                                       { keys:27 }, 
                                                       onKeyEvent, 
                                                       "keypress"
                                                   ); 
                                                   
                oKeyListener3.enable();




                //E.on(document, "keydown", function(e) { alert("keydown"); });
                //E.on(document, "keyup", function(e) { alert("keyup"); });
                //E.on(document, "keypress", function(e) { alert("keypress"); });
            
            });
            */
        })();

		</script>

	</head>
	<body>
         <div id="out"></div>
	</body>
</html><!-- competitor.corp.yahoo.com compressed/chunked Fri Jun 22 14:50:14 PDT 2007 -->
